<%@ include file="/WEB-INF/pages/common/taglibs.jsp"%>
<%@ include file="/WEB-INF/pages/common/checkpermission.jsp" %>
<s:if test='#attr.user.userRole!="O"'>
    <c:redirect url="/index.jsp"/>
</s:if>
<script type="text/javascript">
    function saveRecord() {
    	var currentForm = document.forms["addForm"];
        currentForm.elements["erecordModel.recordName"].value = currentForm.elements["erecordModel.recordName"].value.trim();
        currentForm.elements["erecordModel.yearStr"].value = currentForm.elements["erecordModel.yearStr"].value.trim();
        currentForm.elements["erecordModel.refNo"].value = currentForm.elements["erecordModel.refNo"].value.trim();
        currentForm.elements["erecordModel.source"].value = currentForm.elements["erecordModel.source"].value.trim();
        currentForm.elements["erecordModel.appellee"].value = currentForm.elements["erecordModel.appellee"].value.trim();
        currentForm.elements["erecordModel.undertaker"].value = currentForm.elements["erecordModel.undertaker"].value.trim();
        currentForm.elements["erecordModel.caseReason"].value = currentForm.elements["erecordModel.caseReason"].value.trim();
        currentForm.elements["erecordModel.remark"].value = currentForm.elements["erecordModel.remark"].value.trim();
        if(isEmpty(currentForm.elements["erecordModel.recordName"].value)){
            alert('<s:text name="label.erecord.required"/>');
            return;            
        }
        if(isEmpty(currentForm.elements["erecordModel.yearStr"].value)){
            alert('<s:text name="label.year.required"/>');
            return;
        }
        if(isEmpty(currentForm.elements["erecordModel.refNo"].value)){
            alert('<s:text name="label.refno.required"/>');
            return;
        }
        if(isEmpty(currentForm.elements["erecordModel.source"].value)){
            alert('<s:text name="label.source.required"/>');
            return;
        }
        if(isEmpty(currentForm.elements["erecordModel.appellee"].value)){
            alert('<s:text name="label.appellee.required"/>');
            return;
        }
        if(isEmpty(currentForm.elements["erecordModel.caseDate"].value)){
            alert('<s:text name="label.casedate.required"/>');
            return;
        }
        if(isEmpty(currentForm.elements["erecordModel.caseReason"].value)){
            alert('<s:text name="label.casereason.required"/>');
            return;
        }
        if(isEmpty(currentForm.elements["erecordModel.upload"].value)){
            alert('<s:text name="label.erecord.attach.required"/>');
            return;            
        }

        if(!validateForm_int(currentForm.elements["erecordModel.yearStr"])){
            alert('<s:text name="label.year.error"/>');
            return;
        }
        if(parseInt(currentForm.elements["erecordModel.yearStr"].value)<1900 ||parseInt(currentForm.elements["erecordModel.yearStr"].value)>2050){
            alert('<s:text name="label.year.error"/>');
            return;
        }

        if(!validateForm_date(currentForm.elements["erecordModel.caseDate"])){
            alert('<s:text name="label.casedate.error"/>');
            return;
        }

        if(!checkEnd(currentForm.elements["f_file"].value.toUpperCase(),".PDF")){
            alert('<s:text name="label.upload.format.error"/>');
            return;
        }


        submitForm("addForm", "add.action");
    }

    function cancelRecord() {
        submitForm("addForm", "search.action");
    }

        function fclick(obj, objButton) {
        with (obj) {
            scrollTop = event.y - offsetHeight / 2
            style.posLeft = event.x - offsetWidth / 2
        }
    }

</script>

<s:form name="addForm" action="" method="post" enctype="multipart/form-data">
    <table align="center" cellpadding="0" cellspacing="0" class="body_content full_width">
        <tr>
            <td align="left" valign="bottom" class="main_page_content_icon" width="4%">
                <img src='<c:url value="/images/body-icon_check.gif"/>' width="29" height="44">
            </td>
            <td valign="bottom" class="page_title_bg" width="96%">
                <span class="page_title">
                    <s:text name="label.new.erecord"/>
                </span>
            </td>
        </tr>
        <tr>
            <td class="subcontent" colspan="2">&nbsp;</td>
        </tr>
    </table>
    
    <table border="0" align="center" cellpadding="0" cellspacing="0" class="body_content full_width bordered">
		<tr class="even">
			<td class="form_label_padded" width="10%" nowrap><s:text name="label.name.erecord" /></td>
			<td class="form_label_padded" width="2%">:</td>
			<td class="txtData" align="left" width="38%"><s:textfield name="erecordModel.recordName" maxlength="100" /></td>
			<td class="form_label_padded" width="10%" nowrap><s:text name="label.type.erecord" /></td>
			<td class="form_label_padded" width="2%">:</td>
			<td class="txtData" align="left" width="38%">
                <s:select list="typeList" name="erecordModel.recordType" listKey="value" listValue="label"/>
            </td>
		</tr>
		<tr class="odd">
			<td class="form_label_padded" width="10%" nowrap><s:text name="label.year"/></td>
			<td class="form_label_padded" width="2%">:</td>
			<td class="txtData" align="left" width="38%"><s:textfield name="erecordModel.yearStr" maxlength="4"/></td>
			<td class="form_label_padded" width="10%" nowrap><s:text name="label.ref.no" /></td>
			<td class="form_label_padded" width="2%">:</td>
			<td class="txtData" align="left" width="38%">
                <s:textfield name="erecordModel.refNo" maxlength="25"/>
            </td>
		</tr>
		<tr class="even">
			<td class="form_label_padded" width="10%" nowrap><s:text name="label.source"/></td>
			<td class="form_label_padded" width="2%">:</td>
			<td class="txtData" align="left" width="38%"><s:textfield name="erecordModel.source" maxlength="100" /></td>
			<td class="form_label_padded" width="10%" nowrap><s:text name="label.appellee"/></td>
			<td class="form_label_padded" width="2%">:</td>
			<td class="txtData" align="left" width="38%">
                <s:textfield name="erecordModel.appellee" maxlength="25"/>
            </td>
		</tr>
		<tr class="odd">
			<td class="form_label_padded" width="10%" nowrap><s:text name="label.casedate"/></td>
			<td class="form_label_padded" width="2%">:</td>
			<td class="txtData" align="left" width="38%"><cl:date name="erecordModel.caseDate"/>(<s:text name='label.date.format'/>)</td>
			<td class="form_label_padded" width="10%" nowrap><s:text name="label.undertaker"/></td>
			<td class="form_label_padded" width="2%">:</td>
			<td class="txtData" align="left" width="38%">
                <s:textfield name="erecordModel.undertaker" maxlength="25" />
            </td>
		</tr>
		<tr class="even">
			<td class="form_label_padded" width="10%" nowrap><s:text name="label.caseresaon"/></td>
			<td class="form_label_padded" width="2%">:</td>
			<td class="txtData" align="left" width="38%" colspan="4"><s:textfield name="erecordModel.caseReason" maxlength="500" size="150"/></td>
		</tr>
		<tr class="odd">
			<td class="form_label_padded" width="10%" nowrap><s:text name="label.remark"/></td>
			<td class="form_label_padded" width="2%">:</td>
			<td class="txtData" align="left" width="38%" colspan="4"><s:textfield name="erecordModel.remark" maxlength="500" size="150"/></td>
		</tr>
        <tr class="even">
            <td class="form_label_padded" width="10%" nowrap><s:text name="label.attach.erecord"/></td>
            <td class="form_label_padded" width="2%">:</td>
            <td class="txtData" align="left" colspan="4">
                <input id="f_file" readonly="true">&nbsp;
                <input type="button" onmouseover="fclick(t_file,this);" value="<s:text name='label.browse'/>" class="button">
                <s:file name="erecordModel.upload" contentEditable="false"
                        style="position:absolute;filter:alpha(opacity=0);width:30px;"
                        id="t_file" onchange="f_file.value=this.value"/>
            </td>
        </tr>
        <tr class="odd">
            <td class="txtData" colspan="6">
                 <input type="button" class="button" value="<s:text name='label.save'/>" onclick="saveRecord();">
                 <input type="button" class="button" value="<s:text name='label.back'/>" onclick="cancelRecord();">
            </td>
        </tr>        		
	</table>
                 

</s:form>
